package top.coolxue.common.result;

import com.github.pagehelper.Page;

import java.io.Serializable;
import java.util.List;

public class JsonPageResult<T> extends JsonResult implements Serializable {
    private static final long serialVersionUID = 1L;

    private long total;        //总条数
    private int pageSize;           //每页数量
    private int totalPageNum;      //总页码数
    private int pageNo;          //当前页码

    public JsonPageResult(List<T> items, Page page) {
        super(items);
        this.total = page.getTotal();
        this.pageNo = page.getPageNum();
        this.pageSize = page.getPageSize();
        if (total > 0) {
            int x1 = (int) (this.total / this.pageSize);
            int x2 = this.total % this.pageSize != 0 ? 1 : 0;
            this.totalPageNum = x1 + x2;
        } else {
            this.totalPageNum = 0;
        }
    }

    public JsonPageResult(List<T> items, Page page, boolean status, String message) {
        super(status, message, items);
        this.total = page.getTotal();
        this.pageNo = page.getPageNum();
        this.pageSize = page.getPageSize();
        if (total > 0) {
            int x1 = (int) (this.total / this.pageSize);
            int x2 = this.total % this.pageSize != 0 ? 1 : 0;
            this.totalPageNum = x1 + x2;
        } else {
            this.totalPageNum = 0;
        }
    }

    public JsonPageResult(List<T> items, long total, int pageNo, int pageSize) {
        super(items);
        this.total = total;
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        if (total > 0) {
            int x1 = (int) (this.total / this.pageSize);
            int x2 = this.total % this.pageSize != 0 ? 1 : 0;
            this.totalPageNum = x1 + x2;
        } else {
            this.totalPageNum = 0;
        }

    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPageNum() {
        return totalPageNum;
    }

    public void setTotalPageNum(int totalPageNum) {
        this.totalPageNum = totalPageNum;
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }
}
